package com.tangxz.generate_code.util;

import lombok.extern.slf4j.Slf4j;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;


@Slf4j
public class ResourceUtil {
    /**
     * 通过绝对定位在 config目录下 解析配置文件
     * C:\Users\Administrator\Desktop\tangxz-code\config\123.properties
     * @param filePath
     * @return
     */
    public static ResourceBundle loadResource(String filePath) {
        PropertyResourceBundle prb = null;
        BufferedInputStream bis = null;
        filePath = System.getProperty("user.dir") + File.separator + "config" + File.separator + filePath + ".properties";

        try {
            bis = new BufferedInputStream(new FileInputStream(filePath));
            prb = new PropertyResourceBundle(bis);
            bis.close();
            log.debug(" JAR方式部署，通过config目录读取配置：" + filePath);
        } catch (IOException ignored) {
        } finally {
            if (bis != null) {
                try {
                    bis.close();
                } catch (IOException var12) {
                    var12.printStackTrace();
                }
            }

        }
        return prb;
    }
}
